package com.commerce.constellation.tools;

import android.content.Context;

import com.commerce.constellation.entity.Pairs;
import com.commerce.constellation.R;

import java.util.HashMap;
import java.util.Map;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.POST;

public class RetrofitCall  {

    private interface Constellation{
        @FormUrlEncoded
        @POST("constellation/getAll")
        Call<ResponseBody>  getFortune(@FieldMap Map<String,String> request);
    }

    private interface Xzpd{
        @FormUrlEncoded
        @POST("xzpd/query")
        Call<Pairs>  getPair(@FieldMap Map<String,String> request);
    }

    public static Call<ResponseBody> getConstellationCall(
            Context context, String consName, String type){
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://web.juhe.cn:8080/")
                .build();
        Constellation constellation = retrofit.create(Constellation.class);
        HashMap<String, String> request = new HashMap<>();
        request.put("key",context.getString(R.string.FortuneID));
        request.put("consName",consName);
        request.put("type",type);
        Call<ResponseBody> fortune = constellation.getFortune(request);
        return fortune ;
    }

    public static Call<Pairs> postXzpdCall(
            Context context, String men, String women){
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("http://apis.juhe.cn/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        Xzpd xzpd = retrofit.create(Xzpd.class);
        HashMap<String, String> request = new HashMap<>();
        request.put("men",men);
        request.put("women",women);
        request.put("key",context.getString(R.string.PairID));
        Call<Pairs> pair = xzpd.getPair(request);
        return pair;
    }

}
